package com.ruoyi.ma.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.ruoyi.ma.domain.vo.MaBaseManifestStandardimportVo;
import com.ruoyi.ma.domain.vo.MaMaterialManifestImportVo;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ma.domain.vo.MaBaseManifestStandardVo;
import com.ruoyi.ma.domain.bo.MaBaseManifestStandardBo;
import com.ruoyi.ma.service.IMaBaseManifestStandardService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 甲供材标准材料清单
 *
 * @author tll
 * @date 2024-11-26
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/ma/baseManifestStandard")
public class MaBaseManifestStandardController extends BaseController {

    private final IMaBaseManifestStandardService iMaBaseManifestStandardService;

    /**
     * 查询甲供材标准材料清单列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<MaBaseManifestStandardVo> list(MaBaseManifestStandardBo bo, PageQuery pageQuery) {
        return iMaBaseManifestStandardService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出甲供材标准材料清单列表
     */
    @SaCheckLogin
    @Log(title = "甲供材标准材料清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(MaBaseManifestStandardBo bo, HttpServletResponse response) {
        List<MaBaseManifestStandardVo> list = iMaBaseManifestStandardService.queryList(bo);
        ExcelUtil.exportExcel(list, "甲供材标准材料清单", MaBaseManifestStandardVo.class, response);
    }

    /**
     * 获取下载模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil.exportExcel(new ArrayList<>(), "标准清单", MaBaseManifestStandardimportVo.class, response);
    }

    /**
     * 获取甲供材标准材料清单详细信息
     *
     * @param maStandardId 主键
     */
    @SaCheckLogin
    @GetMapping("/{maStandardId}")
    public R<MaBaseManifestStandardVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long maStandardId) {
        return R.ok(iMaBaseManifestStandardService.queryById(maStandardId));
    }

    /**
     * 新增甲供材标准材料清单
     */
    @SaCheckLogin
    @Log(title = "甲供材标准材料清单", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody MaBaseManifestStandardBo bo) {
        return toAjax(iMaBaseManifestStandardService.insertByBo(bo));
    }

    /**
     * 修改甲供材标准材料清单
     */
    @SaCheckLogin
    @Log(title = "甲供材标准材料清单", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody MaBaseManifestStandardBo bo) {
        return toAjax(iMaBaseManifestStandardService.updateByBo(bo));
    }

    /**
     * 删除甲供材标准材料清单
     *
     * @param maStandardIds 主键串
     */
    @SaCheckLogin
    @Log(title = "甲供材标准材料清单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{maStandardIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] maStandardIds) {
        return toAjax(iMaBaseManifestStandardService.deleteWithValidByIds(Arrays.asList(maStandardIds), true));
    }

    /**
     * 查询甲供材标准材料清单列表不分页
     */
    @SaCheckLogin
    @GetMapping("/allList")
    public R<List<MaBaseManifestStandardVo>> allList(MaBaseManifestStandardBo bo) {
        return R.ok(iMaBaseManifestStandardService.allList(bo));
    }
}
